//
//  LGOperationReportController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/7/18.
//  手术报告列表

#import "LGOperationReportController.h"
//出院证明书
#import "LGRecordHospitalController.h"
#import "LGRecordHospitalController2.h"
//PCL报告详情
#import "LGPCIReportDetailController.h"
#import "LGOperationReportCell.h"
@interface LGOperationReportController ()<UITableViewDelegate,UITableViewDataSource>

/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation LGOperationReportController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"手术相关报告";
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight)];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/Visitrecords/shoussReportList" parameters:@{@"patient_id":self.patientid,@"shouss_date":self.operatDate} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(code == 200){
            self.dataArray = returnData;
        }
        [self.tableView reloadData];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGOperationReportCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    if([LGNSString(tempDic[@"report_type"]) isEqualToString:@"500"]){
        //调用出院证明书
        if([LGNSString(tempDic[@"version"]) isEqualToString:@"1"]){
            LGRecordHospitalController *controller = [[LGRecordHospitalController alloc]init];
            controller.recordId = LGNSString(tempDic[@"record_id"]);
            [self.navigationController pushViewController:controller animated:YES];
        }else{
            LGRecordHospitalController2 *controller = [[LGRecordHospitalController2 alloc]init];
            controller.recordId = LGNSString(tempDic[@"record_id"]);
            [self.navigationController pushViewController:controller animated:YES];
        }
    }else{
        //调用PCL报告详情
        LGPCIReportDetailController *controller = [[LGPCIReportDetailController alloc]init];
        controller.recordid = LGNSString(tempDic[@"record_id"]);
        controller.type = LGNSString(tempDic[@"report_type"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}



-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGOperationReportCell class] forCellReuseIdentifier:@"cell"];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(8))];
    }
    return _tableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
